{==============================================================================}
{  Acroprise Multi-Language Components                                         }
{                                                                              }
{  Copyright (C), 1999-2012, Acroprise Inc.                                    }
{  http://www.acroprise.com.tw                                                 }
{  ALL RIGHTS RESERVED                                                         }
{                                                                              }
{  Author   : Mustapha.Wang                                                    }
{  Version  : 4.1.15.2159                                                      }
{  Creation : 2002/05/06                                                       }
{  Revision :                                                                  }
{  Task     :                                                                  }
{==============================================================================}
unit acroMultiMessageBox;
{$I acroMultiLang.Inc}
interface
uses
  Classes,SysUtils,
  {$IFDEF MSWindows}
  Windows,
  {$ENDIF}
  {$IFDEF Delphi15High}
  System.UITypes,
  {$ELSE}
  Dialogs,
  {$ENDIF}
  acroMultiInterface,
  acroMultiDD;
type
  TacroMsgBox=class(TComponent)
  private
    FSystemLCID:Boolean;
    FLCID:string;
    FDDName:string;
    procedure SetLCID(const Value: string);
    procedure SetSystemLCID(const Value: Boolean);
  public
    constructor Create(AOwner:TComponent);override;
    function  GetDisplayValue(ADDKey:string;ASeqNo:string='0'):string;overload;
    function  GetDisplayValue(ADDKey:string;ASeqNo:string;var AIsFound:Boolean):string;overload;
    procedure ShowMessage(Msg:string;ASeqNo:string='0');
    procedure ShowMessage2(Msg:string;const Args: array of const;
              ASeqNo:string='0');
    procedure ShowMessage3(Msg:string;ArgList:TStrings;ASeqNo:string='0');
    {$IFDEF MSWindows}
    function  MessageBox(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
              ASeqNo:string='0'):integer;
    function  MessageBox2(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
              const ArgsText,ArgsCaption: array of const;ASeqNo:string='0'):integer;
    {$ENDIF}
    function  MessageDlg(Msg:string;DlgType:TMsgDlgType;
              Buttons:TMsgDlgButtons;HelpCtx:Longint;ASeqNo:string='0'):integer;
    function  MessageDlg2(Msg:string;DlgType:TMsgDlgType;
              Buttons:TMsgDlgButtons;HelpCtx:Longint;const Args: array of const;
              ASeqNo:string='0'):integer;
  published
    property LCID:string read FLCID write SetLCID;
    property SystemLCID:Boolean read FSystemLCID write SetSystemLCID;
    property DDName:string read FDDName write FDDName;
  end;

  procedure MultiShowMessage(Msg,ALCID:string;ASeqNo:string='0';
            ADDName:string='MessageDD');
  procedure MultiShowMessage2(Msg,ALCID:string;const Args: array of const;
            ASeqNo:string='0';ADDName:string='MessageDD');
  {$IFDEF MSWindows}
  function  MultiMessageBox(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
            ALCID:string;ASeqNo:string='0';ADDName:string='MessageDD'):integer;
  function  MultiMessageBox2(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
            ALCID:string;const ArgsText,ArgsCaption: array of const;ASeqNo:string='0';
            ADDName:string='MessageDD'):integer;
  {$ENDIF}

  function  MultiMessageDlg(Msg:string;DlgType:TMsgDlgType;
            Buttons:TMsgDlgButtons;HelpCtx:Longint;ALCID:string;ASeqNo:string='0';
            ADDName:string='MessageDD'):Integer;
  function  MultiMessageDlg2(Msg:string;DlgType:TMsgDlgType;
            Buttons:TMsgDlgButtons;HelpCtx:Longint;ALCID:string;
            const Args: array of const;ASeqNo:string='0';
            ADDName:string='MessageDD'):Integer;

implementation

procedure MultiShowMessage(Msg,ALCID:string;ASeqNo:string='0';ADDName:string='MessageDD');
begin
  g_MultiFramework.ShowMessage(acroDDStorage.GetDisplayValue(ADDName,Msg,ALCID,ASeqNo));
end;

procedure MultiShowMessage2(Msg,ALCID:string;const Args: array of const;ASeqNo:string='0';ADDName:string='MessageDD');
begin
  Msg:=acroDDStorage.GetDisplayValue(ADDName,Msg,ALCID,ASeqNo);
  if High(Args)>=0 then Msg:=Format(Msg,Args);
  g_MultiFramework.ShowMessage(Msg);
end;

{$IFDEF MSWindows}
function MultiMessageBox(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
  ALCID:string;ASeqNo:string='0';ADDName:string='MessageDD'):integer;
begin
  Result:=MessageBox(hWnd,
    PChar(acroDDStorage.GetDisplayValue(ADDName,lpText,ALCID,ASeqNo)),
    PChar(acroDDStorage.GetDisplayValue(ADDName,lpCaption,ALCID,ASeqNo)),uType);
end;

function MultiMessageBox2(hWnd:HWND;lpText,lpCaption:PChar;uType:Cardinal;
  ALCID:string;const ArgsText,ArgsCaption: array of const;ASeqNo:string='0';
  ADDName:string='MessageDD'):integer;
var
  sText,sCaption:String;
begin
  sText:=acroDDStorage.GetDisplayValue(ADDName,lpText,ALCID,ASeqNo);
  if High(ArgsText)>=0 then sText:=Format(sText,ArgsText);
  sCaption:=acroDDStorage.GetDisplayValue(ADDName,lpCaption,ALCID,ASeqNo);
  if High(ArgsCaption)>=0 then sCaption:=Format(sCaption,ArgsCaption);
  Result:=MessageBox(hWnd,PChar(sText),PChar(sCaption),uType);
end;
{$ENDIF}
function MultiMessageDlg(Msg:string;DlgType:TMsgDlgType;Buttons:TMsgDlgButtons;
  HelpCtx:Longint;ALCID:string;ASeqNo:string='0';ADDName:string='MessageDD'):Integer;
begin
  Result:=g_MultiFramework.MessageDlg(acroDDStorage.GetDisplayValue(ADDName,Msg,ALCID,ASeqNo),
    DlgType,Buttons,HelpCtx);
end;

function MultiMessageDlg2(Msg:string;DlgType:TMsgDlgType;Buttons:TMsgDlgButtons;
  HelpCtx:Longint;ALCID:string;const Args: array of const;ASeqNo:string='0';
  ADDName:string='MessageDD'):Integer;
begin
  Msg:=acroDDStorage.GetDisplayValue(ADDName,Msg,ALCID,ASeqNo);
  if High(Args)>=0 then Msg:=Format(Msg,Args);
  Result:=g_MultiFramework.MessageDlg(Msg,DlgType,Buttons,HelpCtx);
end;

constructor TacroMsgBox.Create(AOwner: TComponent);
begin
  inherited;
end;

function TacroMsgBox.GetDisplayValue(ADDKey:string; ASeqNo: string='0'): string;
var
  vIsFound:Boolean;
begin
  Result:=GetDisplayValue(ADDKey,ASeqNo,vIsFound);
end;

function TacroMsgBox.GetDisplayValue(ADDKey, ASeqNo: string;
  var AIsFound: Boolean): string;
begin
  Result:=acroDDStorage.GetDisplayValue(FDDName,ADDKey,FLCID,ASeqNo,AIsFound);
end;
{$IFDEF MSWindows}
function TacroMsgBox.MessageBox(hWnd: HWND; lpText, lpCaption: PChar;
  uType: Cardinal;ASeqNo:string='0'): integer;
begin
  Result:=MultiMessageBox(hWnd,lpText,lpCaption,uType,FLCID,ASeqNo,FDDName);
end;

function TacroMsgBox.MessageBox2(hWnd: HWND; lpText, lpCaption: PChar;
  uType: Cardinal; const ArgsText,ArgsCaption: array of const; ASeqNo: string): integer;
begin
  Result:=MultiMessageBox2(hWnd,lpText,lpCaption,uType,FLCID,ArgsText,ArgsCaption,ASeqNo,FDDName);
end;
{$ENDIF}
function TacroMsgBox.MessageDlg(Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; HelpCtx: Integer;ASeqNo:string='0'): integer;
begin
  Result:=MultiMessageDlg(Msg,DlgType,Buttons,HelpCtx,FLCID,ASeqNo,FDDName);
end;

function TacroMsgBox.MessageDlg2(Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; HelpCtx: Integer; const Args: array of const;
  ASeqNo: string): integer;
begin
  Result:=MultiMessageDlg2(Msg,DlgType,Buttons,HelpCtx,FLCID,Args,ASeqNo,FDDName);
end;

procedure TacroMsgBox.SetLCID(const Value: string);
begin
  if not FSystemLCID then FLCID:=Value;
end;

procedure TacroMsgBox.SetSystemLCID(const Value: Boolean);
begin
  FSystemLCID := Value;
  if FSystemLCID then FLCID:=InttoStr(GetACP);
end;

procedure TacroMsgBox.ShowMessage(Msg: string;ASeqNo:string='0');
begin
  MultiShowMessage(MSg,FLCID,ASeqNo,FDDName);
end;

procedure TacroMsgBox.ShowMessage2(Msg: string;
  const Args: array of const; ASeqNo:string='0');
begin
  MultiShowMessage2(Msg,FLCID,Args,ASeqNo,FDDName);
end;

procedure TacroMsgBox.ShowMessage3(Msg: string; ArgList: TStrings;
  ASeqNo: string);
var
  i,m,n:integer;
  sText,sText2:string;
begin
  sText2:=acroDDStorage.GetDisplayValue(FDDName,Msg,FLCID,ASeqNo);
  if (ArgList=nil) or (ArgList.Count=0) then sText:=sText2
  else
  begin
    n:=Length(sText2);
    sText:='';
    i:=1;
    m:=0;
    while i<=n do
    begin
      case sText2[i] of
        '%':begin
              if i=n then sText:=sText+sText2[i]
              else
              begin
                case sText2[i+1] of
                  '%':begin
                        sText:=sText+'%';
                        Inc(i);
                      end;
                  's':begin
                        sText:=sText+ArgList[m];
                        Inc(m);
                        Inc(i);
                        if m>=ArgList.Count then
                        begin
                          sText:=sText+Copy(sText2,i+1,n-i);
                          break;
                        end;
                      end;
                  else sText:=sText+sText2[i];
                end
              end;
            end;
        else sText:=sText+sText2[i];
      end;
      Inc(i);
    end;
  end;
  g_MultiFramework.MessageDlg(sText,{$IFDEF Delphi15High}TMsgDlgType.{$ENDIF}mtInformation,[{$IFDEF Delphi15High}TMsgDlgBtn.{$ENDIF}mbOK],0);
end;

end.
